<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :span="5">
            <a-form-item label="封禁IP">
              <a-input placeholder="请输入封禁IP" v-model="queryParam.ip"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="5">
            <a-form-item label="封禁账号">
              <a-input placeholder="请输入封禁账号" v-model="queryParam.username"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="5">
            <a-form-item label="封禁状态">
              <j-dict-select-tag
                v-model="queryParam.bannedState"
                dictCode="login_banned_state"
                placeholder="请选择封禁状态"
                @input="searchQuery"
              />
            </a-form-item>
          </a-col>
          <a-col :span="5" >
            <span style="float: left;overflow: hidden;margin-top:4px" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search" size="small">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px" size="small">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button type="primary" icon="down" @click="handleBatchUnseal">批量解封</a-button>
      <!-- <a-button @click="handleAdd" type="primary" icon="plus" v-has="'SysLoginErrorList:add'">新增</a-button>
      <a-button
        type="primary"
        icon="download"
        @click="handleExportXls('登录错误表')"
        v-has="'SysLoginErrorList:exportXls'"
        >导出</a-button
      >
      <a-upload
        name="file"
        :showUploadList="false"
        :multiple="false"
        :headers="tokenHeader"
        :action="importExcelUrl"
        @change="handleImportExcel"
      >
        <a-button type="primary" icon="import" v-has="'SysLoginErrorList:importXls'">导入</a-button>
      </a-upload>
      <a-dropdown v-if="selectedRowKeys.length > 0" v-has="'SysLoginErrorList:deleteBatch'">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete" />删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down"/></a-button>
      </a-dropdown> -->
    </div>

    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange, getCheckboxProps: getCheckboxProps}"
        @change="handleTableChange"
      >
      <!-- 封禁状态 -->
      <template slot="bannedState" slot-scope="text, record">
        <a-tag color="red" v-if="record.bannedState === '1'">已封禁</a-tag>
        <a-tag color="blue" v-if="record.bannedState === '2'">已解封</a-tag>
      </template>
      </a-table>
    </div>

    <sys-login-error-modal ref="modalForm" @ok="modalFormOk"></sys-login-error-modal>
  </a-card>
</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import SysLoginErrorModal from './modules/SysLoginErrorModal.vue'

export default {
  name: 'SysLoginErrorList',
  mixins: [JeecgListMixin],
  components: { SysLoginErrorModal },
  data() {
    return {
      description: '登录错误表管理页面',
      // 表头
      columns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '封禁时间',
          align: 'center',
          dataIndex: 'createTime'
        },
        {
          title: '封禁IP',
          align: 'center',
          dataIndex: 'ip'
        },
        {
          title: '封禁账号',
          align: 'center',
          dataIndex: 'username'
        },
        {
          title: '封禁状态',
          align: 'center',
          dataIndex: 'bannedState',
          scopedSlots: { customRender: 'bannedState' },
        },
        {
          title: '解封时间',
          align: 'center',
          dataIndex: 'unsealTime',
          customRender: function(text) {
            return !text ? '' : text.length > 10 ? text.substr(0, 10) : text
          }
        },
        {
          title: '解封原因',
          align: 'center',
          dataIndex: 'unsealReason'
        },
        {
          title: '解封人姓名',
          align: 'center',
          dataIndex: 'realname'
        }
      ],
      url: {
        list: '/system/sysLoginError/list',       //登录异常列表接口
        delete: '/system/sysLoginError/delete',
        deleteBatch: '/system/sysLoginError/deleteBatch',
        exportXlsUrl: '/system/sysLoginError/exportXls',
        importExcelUrl: 'system/sysLoginError/importExcel',
      },
    }
  },
  computed: {
    importExcelUrl: function() {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    }
  },
  methods: {
    /*状态是已解封的禁止选中*/
    getCheckboxProps(record) {
      return {
        props: {
          disabled: record.bannedState == '2',
        },
      }
    },
    handleBatchUnseal(){
      if (this.selectedRowKeys.length <= 0) {
        this.$message.warning('请至少选择一条记录！')
        return
      } else {
        var ids = ''
        for (var a = 0; a < this.selectedRowKeys.length; a++) {
          ids += this.selectedRowKeys[a] + ','
        }
        this.$refs.modalForm.edit(ids);
        this.$refs.modalForm.title = "批量解封"; 
      }
    },
    modalFormOk(){
      this.loadData()
      this.selectedRowKeys = []
      this.selectionRows = []
    }

  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
